package logic

import (
	"cart_srv/carl"
	"cart_srv/internal/svc"
	"cart_srv/mobile/mysql"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddCarlLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddCarlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddCarlLogic {
	return &AddCarlLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddCarlLogic) AddCarl(in *carl.AddCarlRequest) (*carl.AddCarlResponse, error) {
	// todo: 添加购物车

	c := mysql.Carl{
		UserId:     in.UserId,
		GoodId:     in.GoodsId,
		Num:        in.Num,
		GoodsPrice: float64(in.GoodsPrice),
		GoodsTitle: in.GoodsTitle,
	}
	//新增
	err := c.AddCarl()

	if err != nil {
		logx.Error("添加失败", err)
		return nil, err
	}

	return &carl.AddCarlResponse{CarlId: int64(c.ID)}, nil
}
